package org.qs.webservice.controller;


import java.io.IOException;
import java.util.HashMap;
import java.util.Map;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.ws.rs.GET;
import javax.ws.rs.HeaderParam;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;
import javax.ws.rs.QueryParam;
import javax.ws.rs.core.Context;
import javax.ws.rs.core.MediaType;

import org.glassfish.jersey.server.mvc.Template;
import org.qs.webservice.exception.QSReadException;
import org.qs.webservice.service.AlipayService;
import org.springframework.stereotype.Component;

import com.sun.jersey.api.view.Viewable;


/**
 * 获取某个区块中素材列表接口
 * @ClassName: BlockRestController 
 * @author xusaike 
 * @date 2015年9月28日 下午2:39:54 
 *
 */
@Component
@Path("/v{version}/alipay")
public class AliPayRestController {
	@Resource
	AlipayService alipayService;
	@GET
	@Produces(MediaType.TEXT_PLAIN)
	@Template
	//@Consumes(MediaType.APPLICATION_FORM_URLENCODED)
    public Viewable index(@HeaderParam("Info-Uuid")String device_identifier,
			@HeaderParam("token")String token,@QueryParam("type")int type,@Context HttpServletResponse response,@Context HttpServletRequest request) {
		HashMap<String,Object> model = null;
		try{
			model =  alipayService.addOrder(device_identifier, token, type);
		} catch (Exception e) {
			Map<String,Object> errorJson = new HashMap<String,Object>();
			errorJson.put("token", token);
			QSReadException.printf(e, "上传头像异常！",errorJson);
			try {
				response.sendRedirect("http://www.iqinshu.cn/");
				return null;
			} catch (IOException e1) {
				e1.printStackTrace();
			}
		}
		return new Viewable("/index",model);
	}

	
}